package com.tan.service;

import com.tan.dom4japi.Dom4j;
import com.tan.dom4jdome.Dom4jImpl;
import com.tan.entity.InfoEntity;
import com.tan.utils.DateUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author 谭永超 [www.tanyongchao.tk:8090/SumDome/index]
 * @Date 2018/8/21 14:43
 * @Description
 */
@Service(value = "dom4jService")
public class Dom4jServiceImpl implements Dom4jService  {
    // 读取xml 文件的地址
    private final String XML_PATH ="av_with_airline_rs.xml";
    @Override
    public List<InfoEntity> allInteger() throws Exception {
        Dom4j dom4j = new Dom4jImpl();
        List<InfoEntity> entities = dom4j.getInfoEntitys(XML_PATH);
        List<InfoEntity> infoEntities = new ArrayList<InfoEntity>();
        String date = "2014-04-25";
        //Date date1 = new Date();
        //System.out.println(DateUtils.currentDate(date1));
        for (InfoEntity infoEntity:
        entities) {
            if(infoEntity.getDepartureDate().equals(DateUtils.formatDate(date))){
                infoEntities.add(infoEntity);
            }
        }
        return infoEntities;
    }

    @Override
    public List<InfoEntity> selectByPlaceAndDate(String departureAirportName, String arrivalAirportName, String date) {
        Dom4j dom4j = new Dom4jImpl();
        return dom4j.selectInfo(departureAirportName,arrivalAirportName,DateUtils.formatDate(date),XML_PATH);
    }
}
